//8888
//  AppDelegate.m
//  XWZ_News_Work
//
//  Created by dllo on 16/1/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "firstPageViewController.h"
#import "UMSocial.h"
#import "readingAndOrderViewController.h"
@interface AppDelegate ()
@property (nonatomic , strong) UITabBarController *tabC;
@property (nonatomic , strong) UIView *viewN;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
//    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  
    //夜间模式
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nightAction) name:@"夜间模式" object:nil];
    //日间模式
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayAction) name:@"日间模式" object:nil];
    
 
    
    [UMSocialData setAppKey:@"507fcab25270157b37000010"];
    
    [self goInMain];

    
    self.viewN = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.viewN.userInteractionEnabled = NO;
        self.viewN.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.500];
    

    
    
    if (YES == [[NSUserDefaults standardUserDefaults] boolForKey:@"isNight"]) {
        
        [self.window addSubview:self.viewN];
        
    } else {
        
        [self.viewN removeFromSuperview];
    }
    
    return YES;
}

- (void)goInMain
{

    NewViewController *newVC  = [[NewViewController alloc]init];
    UINavigationController *newNC = [[UINavigationController alloc]initWithRootViewController:newVC];
    UIImage *newsImage = [UIImage imageNamed:@"tabbar_icon_news_highlight"];
    newsImage = [newsImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    newVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"新闻" image:[UIImage imageNamed:@"tabbar_icon_news_normal"] selectedImage:newsImage];
    
    
    firstPageViewController *firstVC = [[firstPageViewController alloc] init];
    UINavigationController *firstNC = [[UINavigationController alloc]initWithRootViewController:firstVC];
    UIImage *listenImage = [UIImage imageNamed:@"tabbar_icon_media_highlight"];
    listenImage = [listenImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    firstVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"视听" image:[UIImage imageNamed:@"tabbar_icon_media_normal"] selectedImage:listenImage];
    

    

    [[FMDBSingleton FMDBDataBase] openDB];
    readingAndOrderViewController *readerVC = [[readingAndOrderViewController alloc]init];

    UINavigationController *readerNC = [[UINavigationController alloc]initWithRootViewController:readerVC];
    UIImage *readImage = [UIImage imageNamed:@"tabbar_icon_reader_highlight"];
    readImage = [readImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    readerVC.tabBarItem =  [[UITabBarItem alloc] initWithTitle:@"阅读" image:[UIImage imageNamed:@"tabbar_icon_reader_normal"] selectedImage:readImage];
    
    
    TopicViewController *topicVC = [[TopicViewController alloc]init];
    UINavigationController *topicNC = [[UINavigationController alloc]initWithRootViewController:topicVC];
    UIImage *findImage = [UIImage imageNamed:@"tabbar_icon_found_highlight"];
    findImage = [findImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    topicVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@"tabbar_icon_found_normal"] selectedImage:findImage];
    
    
    
    MyViewController *myVC = [[MyViewController alloc]init];
    UINavigationController *myNC = [[UINavigationController alloc]initWithRootViewController:myVC];
    UIImage *userImage = [UIImage imageNamed:@"tabbar_icon_me_highlight"];
    userImage = [userImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    myVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"tabbar_icon_me_normal"] selectedImage:userImage];
    
    self.tabC = [[UITabBarController alloc]init];
    self.tabC.viewControllers = [NSArray arrayWithObjects:newNC,readerNC,firstNC,topicNC,myNC, nil];
    
    self.tabC.tabBar.tintColor = [UIColor redColor];
    self.window.rootViewController = self.tabC;

}



- (void)nightAction
{
   
        [self.window addSubview:self.viewN];
}

- (void)dayAction
{
    [self.viewN removeFromSuperview];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
